package com.lei.design.singleton;

import java.util.Objects;

/**
 * @Author LeiXiaoLei
 * @Date 2022/5/20 09:28
 * @Version 1.0
 */
public class Singleton1 {
    // volatile关键字去报 当uniqueInstance变量初始化成Singleton1实例时，多个线程正确的处理uniqueInstance变量
    private volatile static Singleton1 uniqueInstance;

    private Singleton1() {
    }

    public static Singleton1 getInstance() {
        if (Objects.isNull(uniqueInstance)) {
            synchronized (Singleton1.class) {
                if (Objects.isNull(uniqueInstance))
                    uniqueInstance = new Singleton1();
            }
        }
        return uniqueInstance;
    }
}
